<?php

/**
 * @author CuongNQ
 */
class SqlTicketTable {

    static function SqlTicketUser() {
        $sql = ' INSERT INTO user(email, password, apiKey, status) values(?, ?, ?, 0) ';
        return $sql;
    }

    static function SqlInsetTicket() {
        return "INSERT INTO ticket (
                                    ticket.partyId,
                                    ticket.ownerID,
                                    ticket.ticketCatID,
                                    ticket.ticketCode,
                                    ticket.dateCreate
                            )
                            VALUES
                                    (
                                            ?,?,?,?, CURRENT_TIMESTAMP ()
                                    )";
    }

    static function SqlSelectTicket($nameColum) {

        $where = " WHERE  " . $nameColum . " = ?";
        $sql = "SELECT
                    ticket.id,
                    ticket.partyId,
                    ticket.ticketCode,
                    ticket.dateCreate,
                    ticket.ownerID,
                    ticket.isValid,
                    ticket.isConsumed,
                    ticket.comsumeDate,
                    ticket.ticketCatID,
                    ticket.receptionistID
            FROM
                    ticket";

        $sql .= $where;
        return $sql;
    }

    static function SqlUpdateTicket() {
        return "UPDATE ticket
                SET ticket.ownerID = ?, ticket.partyId = ?,
                 ticket.ticketCatID = ?
                WHERE
                        ticket.id = ?";
    }

    static function SqlConsumeTicket() {
        return "UPDATE ticket
                SET ticket.ownerID = ?, isConsumed = 1,
                 ticket.comsumeDate = CURRENT_TIMESTAMP (),
                 ticket.receptionistID = ?
                WHERE
                        ticket.ticketCode = ?
                AND ticket.isValid = 1 ";
    }
    static function SqlInsetTransference() {
        return "INSERT INTO transference (
                  from,
                 `to,
                  ticketID,
                  transferTime
                )
                VALUES
                (
                    ?,?,?,CURDATE()
                )";
    }
}
